<?php

namespace app\web\controller;

use think\App;
use think\Controller;
use think\facade\Request;
use app\web\services\ProblemService;

class Problem extends Controller
{
    public function __construct(Request $request = null, App $app = null)
    {
        parent::__construct($request, $app);
        $this->ProblemService = new ProblemService();
    }


    /**
     * 导航栏处理
     */
    public function getNavMsg()
    {
        $res = $this->ProblemService->getNavMsg();
        if ($res['status'] != 0) {
            $this->error('执行错误');
        }
        $res = $res['data'];
        foreach ($res as $k => $v) {
            if ($v['states'] == 1) {
                $this->assign("title", $v['title']);
            }
        }
        $this->assign("navdata", $res);
    }

    /**
     * 网站首页
     */
    public function index()
    {
        $this->getNavMsg();
        if(!Request::isPost()){
            $list = $this->ProblemService->listt();
            $data = Request::param();
            $data['title'] = empty($data['title'])?"":$data['title'];
            $this->assign('data',$data);
            $this->assign('list',$list);
            $this->assign('page',$list['page']);
            return $this->fetch();
        }else{
            $list = $this->ProblemService->listt();
            $data = Request::param();
            $this->assign('list',$list);
            $this->assign('data',$data);
            $this->assign('page',$list['page']);
            return $this->fetch();
        }
    }


    /**
     * @param 查看问题内容
     */
    public function problem_detail(){
        $this->getNavMsg();
        $data = $this->ProblemService->potlist();
        $list = $this->ProblemService->pocket();
        $this->assign("list",$list);
        $this->assign('data',$data);
        return $this->fetch();
    }
}